package work.vcloud.baseinfo.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import work.vcloud.baseinfo.utils.HttpUtil;
import work.vcloud.frame.controller.BaseController;
import work.vcloud.frame.dao.OpenDao;
import work.vcloud.frame.vo.OutputVo;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Version: 1.0
 * @ClassName： StaffController
 * @Description：
 * @Author： EvanZhao
 * @DateTime： 2022-08-18 9:54
 */

@RestController
@Scope("prototype")
public class StaffController extends BaseController {

    @Resource
    OpenDao openDao;

    /**
     * 保存离职记录
     * @return
     */
    @RequestMapping("api/saveLeaveOfficeUser")
    public OutputVo saveLeaveOfficeUser() {
        try {
            Map<String, Object> map = getParameterMap();
            map.remove("page");
            //删除离职记录
			map.put("sqlMapId", "dimission.delete");
            openDao.delete(map);
            String teachers = map.get("fk_teachers").toString();
            for (String teacherId: teachers.split(",")){
                //保存离职记录
                String fk_teacher = teacherId.replace("'","");
                map.put("fk_teacher", fk_teacher);
                map.put("sqlMapId", "dimission.insert");
                openDao.insert(map);
            }
            //修改教职工状态
            map.put("status", "99");
            map.put("sqlMapId", "employ.updateTeacher");
            openDao.update(map);
            return output("0000");
        } catch (Exception e) {
            e.printStackTrace();
            return output("9999");
        }
    }

}
